﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Lab_Management_System
{
    /// <summary>
    /// Represents lab computers.
    /// </summary>
    internal class Computer
    {
        #region Fields
        private string _computerName;
        private Session _currentSession;
        private bool _isDisabled;
        #endregion

        #region Properties
        /// <summary>
        /// Gets or sets a value indicating the status of the computer (enabled or disabled).
        /// </summary>
        public bool IsDisabled
        {
            get { return _isDisabled; }
            set { _isDisabled = value;  }
        }

        /// <summary>
        /// Gets or sets the computer name.
        /// </summary>
        public string ComputerName
        {
            get { return _computerName; }
            set { _computerName = value; }
        }

        /// <summary>
        /// Gets the current session.
        /// </summary>
        public Session CurrentSession
        {
            get { return _currentSession; }
            set { _currentSession = value; }
        }
        #endregion

        #region Constructor
        /// <summary>
        /// Creates a new computer object.
        /// </summary>
        /// <param name="computerName">The name of the computer (as seen from the network).</param>
        /// <remarks>
        /// The Kopiko lab currently (Spring 2014) uses the convention of concatenating "kl" and a two digit number.
        /// </remarks>
        public Computer(string computerName)
        {
            _computerName = computerName;
        }
        #endregion

        #region Methods
        /// <summary>
        /// Returns a value indicating that this computer is currently logged into.
        /// </summary>
        /// <returns>Returns true if a user is logged in, else returns false.</returns>
        public bool IsLoggedIn()
        {
            return (_currentSession != null) ? true : false;
        }

        /// <summary>
        /// Creates a new session for the computer.
        /// </summary>
        /// <param name="username">The username of the person logging into the computer.</param>
        public void LogIn(string username)
        {
            //TODO: Write code to handle logins while a session is active as well as logins made by an unknown user.
            if (_currentSession != null)
            {
                
            }
            else if (username == "--Unknown--")
            {

            }
            else
            {
                _currentSession = new Session(username);
            }
        }

        /// <summary>
        /// Logs a user out of the computer and deletes the old session.
        /// </summary>
        /// <param name="username">The username of the person logging out of the computer.</param>
        public void LogOut(string username)
        {
            //TODO: Write code to handle logouts initiated by unexpected users.
            if (username != _currentSession.Username)
            {

            }
            else
            {
                _currentSession.StopSession();
                _currentSession = null;
            }
        }
        #endregion
    }
}
